{% extends 'layout.html' %}
{% block title %}{{ station.station_name }}{% endblock %}
{% block content %}
<div class="row">
    <div class="col" align="center">
        <p><h2>修改基于换电步骤的巡检规则</h2></p>
        <p><h3>{{station.station_name}}</h3></p>
        <form action="/ai_inspect/step_rule_update/{{station.station_id}}/{{rule.rule_id}}/" method="POST" id="inspect_rule_create">
            {% csrf_token %}
            <input type="hidden" name="rule_id" value="{{rule.rule_id}}">
            <input type="hidden" name="station" value="{{rule.station_id}}">
            <table class="table table-striped">
                <tr>
                    <td>巡检算法</td>
                    <td>
                        <select class="form-control" name="algorithm" required>
                            <option value="{{rule.algorithm_id}}">{{rule.algorithm.algorithm_name}}</option>
                            {% for algorithm in algorithms %}
                            <option value="{{algorithm.algorithm_name}}">{{algorithm.algorithm_name}}</option>
                            {% endfor %}
                        </select>
                    </td>
                </tr>
                <tr>
                    <td>摄像头名称</td>
                    <td>
                        <select class="form-control" name="channel" required>
                            <option value="{{rule.channel_id}}">{{rule.channel.channel_name}}</option>
                            {% if channels %}
                                {% for channel in channels %}
                                    <option value="{{channel.channel_id}}">{{channel.channel_number}}-{{channel.channel_name}}</option>
                                {% endfor %}
                            {% endif %}
                        </select>
                    </td>
                </tr>
                <tr>
                    <td>换电步骤</td>
                    <td>
                        <select name="step" class="form-control" required>
                            <option value="{{rule.step.step_id}}">{{rule.step.step_code}}-{{rule.step.step_description}}</option>
                            {% if steps %}
                                {% for step in steps %}
                                    <option value="{{step.step_id}}">{{step.step_code}}-{{step.step_description}}</option>
                                {% endfor %}
                            {% endif %}
                        </select>
                    </td>
                </tr>
                <tr>
                    <td>是否启用</td>
                    <td>
                        <div class="mb-3">
                            <!-- 选项1：启用（当is_active为True时选中） -->
                            <div class="form-check form-check-inline">
                                <input class="form-check-input" type="radio" name="activate"
                                       id="active_true" value="True"
                                       {% if rule.activate %}checked{% endif %}>
                                <label class="form-check-label" for="active_true">启用</label>
                            </div>

                            <!-- 选项2：禁用（当is_active为False时选中） -->
                            <div class="form-check form-check-inline">
                                <input class="form-check-input" type="radio" name="activate"
                                       id="active_false" value="False"
                                       {% if not rule.activate %}checked{% endif %}>
                                <label class="form-check-label" for="active_false">禁用</label>
                            </div>
                        </div>
                    </td>
                </tr>
                <tr>
                    <td><button type="reset" class="btn btn-danger btn-block">重置</button></td>
                    <td><button type="submit" class="btn btn-primary btn-block">提交</button></td>
                </tr>
            </table>
        </form>
        <script>
          $(document).ready(function() {
            $('#inspect_rule_create').validate();
          });
        </script>
    </div>
</div>
<div class="row">
    <div class="col" align="right">
        <a role="button" class="btn btn-danger" href="/ai_inspect/step_rule_delete/{{station.station_id}}/{{rule.rule_id}}">删除规则</a>
    </div>
</div>
{% endblock %}